//
//  PUBLIC.m
//  CareLinkApp_iOS19
//
//  Created by 刘家强 on 16/8/21.
//  Copyright © 2016年 Seven Team. All rights reserved.
//

#import "PUBLIC.h"
#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"

@interface PUBLIC () <UIWebViewDelegate,UIWebViewDelegate, NJKWebViewProgressDelegate>
//@interface PUBLIC () <UIWebViewDelegate>

@property (nonatomic, strong) NJKWebViewProgress *progressProxy;
@property (nonatomic, weak) UIProgressView *progressView;

@end

@implementation PUBLIC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationItem setTitle:@"公益活动"];
    
    UIProgressView *progressView = [[UIProgressView alloc] init];

    progressView.trackTintColor=[UIColor whiteColor];
    
    progressView.progress = 0;
    
    [self.view addSubview:progressView];
    self.progressView = progressView;
    
    [progressView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.offset(0);
        make.height.offset(4);
    }];
    
    // 创建webView & 设置代理
    UIWebView *webView = [[UIWebView alloc] init];
    
    // 添加到父类
    [self.view addSubview:webView];
    
    webView.scalesPageToFit = YES;
    
    [webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(progressView.mas_bottom);
        make.left.right.bottom.offset(0);
    }];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://202.106.210.115:18080/hyde-pluto-h360/nt/appEntrance.htm"]];
    
    [webView loadRequest:request];
    
//    webView.delegate = self;
    
    _progressProxy = [[NJKWebViewProgress alloc] init]; // instance variable
    webView.delegate = _progressProxy;
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
    

    [webView goBack];
    
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    
//    self.progressView = 0;
    
    return YES;
}



-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    
    [self.progressView setProgress:progress animated:YES];
}


@end
